package models

import (
	"gorm.io/gorm"
	"network_srv/basic/config"
	"time"
)

type Collect struct {
	Id        uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId    uint           `gorm:"column:user_id;type:bigint;comment:用户ID;not null;" json:"user_id"`           // 用户ID
	VideoId   uint           `gorm:"column:video_id;type:bigint;comment:课程ID;not null;" json:"video_id"`         // 课程ID
	Title     string         `gorm:"column:title;type:varchar(255);comment:课程标题;not null;" json:"title"`         // 课程标题
	CoverUrl  string         `gorm:"column:cover_url;type:varchar(255);comment:课程封面;not null;" json:"cover_url"` // 课程封面
	Price     float64        `gorm:"column:price;type:decimal(10, 2);comment:课程价格;not null;" json:"price"`       // 课程价格
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (cl *Collect) TableName() string {
	return "collect"
}
func (cl *Collect) GetUserMyCollect() error {
	return config.DB.Where("user_id = ?", cl.UserId).Find(&cl).Error
}
